<template>
  <a-modal :title="title" :after-close="reset" @ok="submit">
    <a-form
      ref="formRef"
      :model="form"
      :rules="rules"
      :label-col="{ style: { width: '80px' } }"
      disabled
    >
      <a-form-item label="ID">
        <a-input v-model:value="form.id" placeholder="标识" />
      </a-form-item>
      <a-form-item label="模板名" name="name">
        <a-input v-model:value="form.name" placeholder="标识" />
      </a-form-item>
      <a-form-item label="模板编号" name="tempKey">
        <a-input v-model:value="form.tempKey" placeholder="标识" />
      </a-form-item>
      <a-form-item label="模板说明" name="title">
        <a-input v-model:value="form.title" placeholder="标识" />
      </a-form-item>
      <a-form-item label="模板内容" name="content">
        <a-input v-model:value="form.content" placeholder="短信id" />
      </a-form-item>
      <a-form-item name="status" label="状态">
        <a-radio-group v-model:value="form.status">
          <a-radio :value="1"> 启用 </a-radio>
          <a-radio :value="2"> 禁用 </a-radio>
        </a-radio-group>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup lang="ts">
import { systemnotificationAddup, systemnotificationinfo } from './api';
import { systemnotification, type Isystemnotification } from './entity';
import { validReg } from '@/utils/validate';

const props = withDefaults(defineProps<{
  data: Partial<Isystemnotification>
}>(),{
})
const title = '详情'
const { formRef, submit, close } = useDialog({ validCallback: save })

let form = $ref(new systemnotification())
watchEffect(() => {
  if (props.data.id) {
    systemnotificationinfo({id:props.data.id, detailType:props.data.type,}).then(res => {
      form.setProps(res)
    })
  }
})

const rules = {
        systemnotificationName: [validReg('required', '请输入用户名')]
}

onMounted(() => {
})
const emit = defineEmits(['change'])
function save() {
    systemnotificationAddup(form).then(() => {
    AntMessage.success('保存成功')
    close()
    emit('change')
  })
}

function reset() {
  form = new systemnotification()
}
</script>

<style lang="less"></style>
